package com.lmx.persistence.service;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lmx.common.context.ActionContextHolder;
import com.lmx.common.util.CommonUtil;
import com.lmx.common.util.HttpRequestUtil;
import com.lmx.common.util.PropertiesFileUtil;
import com.lmx.repoDomain.local.tmodel.Camera;
import com.lmx.repoDomain.local.tmodel.LocalDevice;
import com.lmx.persistence.service.CommonService;
import com.lmx.persistence.service.GenericService;
import com.lmx.persistence.service.local.LocalCameraService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @author huibati 2017年5月23日
 */
@Service
@Scope("prototype")
public class LocalHbeaconService {
	private Log logger = LogFactory.getLog(this.getClass());

	private Properties properties = PropertiesFileUtil.getApplicationProperties();

	@PersistenceContext
	private EntityManager em;
	
	@Autowired
	protected LocalCameraService cameraService;

	@Autowired
	protected GenericService dslJpaService;

	@Autowired
	protected CommonService commonService;

	/**
	 * 获取手环按键对应关系(与原有数据进行对比发生变化->写进文件)
	 * 
	 * @author huibati
	 * @param 2017年9月6日
	 */
	public String getScannerHbeaconData() {
		String dataTnbUrl = properties.getProperty("hbeacon.local.url"); 
		String filePath = properties.getProperty("hbeacon.local.file");
		String path = properties.getProperty("hbeacon.local.path");
		String hbeaconData = HttpRequestUtil.sendGet(dataTnbUrl);// 获取最新对应关系
		logger.debug("netData:" + hbeaconData);
		String relationsDatas = "";
		if (hbeaconData == null) {
			hbeaconData = "";
		} else {
			JSONObject jasonObject = JSONObject.fromObject(hbeaconData);
			if (jasonObject.containsKey("relations")) {
				relationsDatas = jasonObject.getString("relations");
			}
		}
		String beaconRelations = ActionContextHolder.getBeaconRelations();// 原有对应关系
		if (beaconRelations == null) {
			beaconRelations = "";
		}
		logger.debug("beaconRelations:" + beaconRelations);
		logger.debug("hbeaconData:" + relationsDatas);
		// 验证关系数据是否发生变化
		if (beaconRelations.equals(relationsDatas) || "".equals(relationsDatas)) {
			return null;
		} else {
			ActionContextHolder.setBeaconRelations(relationsDatas);
		}
		String dataGHUrl = properties.getProperty("hbeacon.local.guihua.pushDataurl");
		logger.debug("push data guihua URL:" + dataGHUrl);
		if (dataGHUrl == null || "".equals(dataGHUrl)) {

		} else {
			String result = HttpRequestUtil.postData(dataGHUrl, hbeaconData);// 推送至桂花
			logger.debug("push data guihua result:" + result);
		}
		// 写到本地文件
		bufferedWriter(hbeaconData, filePath, path);
		return hbeaconData;
	}

	public void bufferedWriter(String str, String filePath, String rootPath) {
		logger.debug("write data");
		FileWriter fw = null;
		BufferedWriter bw = null;
		try {
			File path = new File(rootPath);
			if (!path.exists()) {
				path.mkdirs();
			}
			File file = new File(filePath);
			if (!file.exists()) {
				file.createNewFile();
			}
			fw = new FileWriter(file);
			bw = new BufferedWriter(fw);
			bw.write(str);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				// bw.flush();
				bw.close();
				fw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * 处理蓝牙路由设备发送的数据信息
	 * 
	 * @author huibati
	 * @param 2017年9月6日
	 */
	public void addDeviceInfo(String dataJson) {
		// dataJson="{\"timestamp\":1501517032,\"scannerHeartbeat\":[{\"scanner\":\"feffaa0c25e9\",\"heartbeat\":1501516863},{\"scanner\":\"feffaaec0362\",\"heartbeat\":1501516866},{\"scanner\":\"feffaa106d1b\",\"heartbeat\":1501516863},{\"scanner\":\"feffaae91819\",\"heartbeat\":1501516865},{\"scanner\":\"feffaa7ba1c6\",\"heartbeat\":1501516865},{\"scanner\":\"feffaa034628\",\"heartbeat\":1501516862},{\"scanner\":\"feffaa45e3c2\",\"heartbeat\":1501516854},{\"scanner\":\"feffaacdc7e6\",\"heartbeat\":1501516859},{\"scanner\":\"feffaaedc702\",\"heartbeat\":1501516862},{\"scanner\":\"feffaaec121a\",\"heartbeat\":1501516868},{\"scanner\":\"feffaaf580d0\",\"heartbeat\":1501516858},{\"scanner\":\"feffaa48ba17\",\"heartbeat\":1501516858},{\"scanner\":\"feffaaf074fe\",\"heartbeat\":1501516879},{\"scanner\":\"feffaad090eb\",\"heartbeat\":1501516856},{\"scanner\":\"feffaac9a6c6\",\"heartbeat\":1501516863},{\"scanner\":\"feffaa123867\",\"heartbeat\":1501516854},{\"scanner\":\"feffaa46325c\",\"heartbeat\":1501516873},{\"scanner\":\"feffaa650e71\",\"heartbeat\":1501516854},{\"scanner\":\"feffaa66adf8\",\"heartbeat\":1501516879},{\"scanner\":\"feffaaaa7634\",\"heartbeat\":1501516872},{\"scanner\":\"feffaac95346\",\"heartbeat\":1501516882},{\"scanner\":\"feffaa6ec8dc\",\"heartbeat\":1501516853},{\"scanner\":\"feffaa4e0cda\",\"heartbeat\":1501516872},{\"scanner\":\"feffaab9ab46\",\"heartbeat\":1501516872},{\"scanner\":\"feffaab61b1f\",\"heartbeat\":1501516873},{\"scanner\":\"feffaa5045fc\",\"heartbeat\":1501516857},{\"scanner\":\"feffaa5bd8ad\",\"heartbeat\":1501516878}]}";
		// 数据样例
		// "[{\"type\":\"swipe\",\"eventId\":\"2d0b42f9-1c93-40a4-8baa-64b70e9e0b7c\",\"data\":[{\"scanner\":\"feffaac89c58\",\"advertiser\":[{\"mac\":\"fe2bbd1985c7\",\"index\":\"5802\",\"timestamp\":1489402625851,\"message\":{\"buttonPressed\":true,\"buttonReleased\":false}}]}]}]";
		// dataJson="{\"type\":\"swipe\",\"eventId\":\"e175490e-c037-4d51-a22f-4dd9774fea8b\",\"data\":[{\"scanner\":\"feffaac89c58\",\"advertiser\":[{\"mac\":\"c10f4c35bdda\",\"index\":\"5743\",\"timestamp\":1489402622288,\"message\":{\"stepCount\":0}},{\"mac\":\"c1c4c7973ec9\",\"index\":\"5722\",\"timestamp\":1489402621398,\"message\":{\"stepCount\":4780}}}]}";
		// dataJson =
		// "{\"timestamp\":1495797155,\"scannerHeartbeat\":[{\"scanner\":\"feffaa3e127c\",\"heartbeat\":1495796983},{\"scanner\":\"feffaa221b7d\",\"heartbeat\":1495797003}]}";

		logger.debug("addDeviceInfo: " + dataJson + "  " + CommonUtil.getCurrTimeForString());
		String localFlag = properties.getProperty("hbeacon.local.flag");
		int dateInterval = Integer.parseInt(properties.getProperty("hbeacon.local.pushData.dateInterval"));
		if (dataJson.startsWith("[") && dataJson.endsWith("]")) {

		} else {
			dataJson = "[" + dataJson + "]";
		}
		JSONArray jsonArray = JSONArray.fromObject(dataJson);
		for (int i = 0; i < jsonArray.size(); i++) {
			JSONObject object = jsonArray.getJSONObject(i);
			String type = "";// 数据中事件类型--桂花
			if (object.containsKey("type")) {
				type = object.getString("type");
			}
			// 华米/桂花 位置or呼叫信息
			if (object.containsKey("data")) {
				JSONArray data = object.getJSONArray("data");
				for (int j = 0; j < data.size(); j++) {
					logger.debug(" scanner " + data.getJSONObject(j).getString("scanner")); // 插入scanner数据hbox消息
					String scannerMac = data.getJSONObject(j).getString("scanner");
					JSONArray macs = data.getJSONObject(j).getJSONArray("advertiser");
					for (int k = 0; k < macs.size(); k++) {
						// 处理华米数据 Start
						if (macs.getJSONObject(k).containsKey("message")
								&& !"".equals(macs.getJSONObject(k).getString("message"))) {
							JSONObject message = macs.getJSONObject(k).getJSONObject("message");
							// 华米按键震动消息
							if (message.containsKey("buttonPressed")
									&& "true".equals(message.getString("buttonPressed"))) {
								Map<String, Object> callingData = new HashMap<String, Object>();
								// 数据样例
								// {"callingData":[{"callingTime":1491960821,"deviceId":"fe2bbd1985c7","scannerId":"f000000000"}]}
								List tempList = new ArrayList<>();
								Map<String, Object> mapTemp = new HashMap<String, Object>();
								if (macs.getJSONObject(k).containsKey("battery")) {
									mapTemp.put("dBattery", macs.getJSONObject(k).getString("battery"));
								}
								mapTemp.put("deviceId", macs.getJSONObject(k).getString("mac"));
								mapTemp.put("scannerId", scannerMac);
								mapTemp.put("callingTime", CommonUtil.getCurrTimes());
								tempList.add(mapTemp);
								callingData.put("callingData", tempList);
								callingData.put("dataSource", "huami");
								callingData.put("localFlag", localFlag);
								logger.debug("calling Data " + JSONObject.fromObject(callingData).toString());
								this.pushHbeaconInfo(JSONObject.fromObject(callingData).toString());
							} else if (message.containsKey("buttonPressed")
									&& "false".equals(message.getString("buttonPressed"))) {
								// 华米按键取消震动消息
								Map<String, Object> callingData = new HashMap<String, Object>();
								// 数据样例
								// {"callingData":[{"cancelTime":1491960821,"deviceId":"fe2bbd1985c7","scannerId":"f000000000"}]}
								List tempList = new ArrayList<>();
								Map<String, Object> mapTemp = new HashMap<String, Object>();
								if (macs.getJSONObject(k).containsKey("battery")) {
									mapTemp.put("dBattery", macs.getJSONObject(k).getString("battery"));
								}
								mapTemp.put("deviceId", macs.getJSONObject(k).getString("mac"));
								mapTemp.put("scannerId", scannerMac);
								mapTemp.put("cancelTime", CommonUtil.getCurrTimes());
								tempList.add(mapTemp);
								callingData.put("callingData", tempList);
								callingData.put("dataSource", "huami");
								callingData.put("localFlag", localFlag);
								logger.debug("cancel calling Data " + JSONObject.fromObject(callingData).toString());
								this.pushHbeaconInfo(JSONObject.fromObject(callingData).toString()); // push按键呼叫cancel数据
							} else {
								Map<String, Object> locationData = new HashMap<String, Object>();
								// 推送json数据
								// {"locationData":[{"deviceId":"fx000000000","dataTime":666666,"scanner":666666}]}
								List tempList = new ArrayList<>();
								Map<String, Object> mapTemp = new HashMap<String, Object>();
								if (macs.getJSONObject(k).containsKey("battery")) {
									mapTemp.put("dBattery", macs.getJSONObject(k).getString("battery"));
								}
								mapTemp.put("deviceId", macs.getJSONObject(k).getString("mac"));
								mapTemp.put("dataTime", CommonUtil.getCurrTimes());
								mapTemp.put("scanner", scannerMac);
								tempList.add(mapTemp);
								locationData.put("locationData", tempList);
								locationData.put("dataSource", "huami");
								locationData.put("localFlag", localFlag);
								logger.debug(" locationData " + JSONObject.fromObject(locationData).toString());
								this.pushHbeaconInfo(JSONObject.fromObject(locationData).toString()); // push位置数据
							}
						}
						// 处理华米数据 end

						// 处理桂花数据 Start
						if ("location".equals(type)) {
							Map<String, Object> locationData = new HashMap<String, Object>();
							// 推送json数据
							// {"locationData":[{"deviceId":"fx000000000","dataTime":666666,"scanner":666666}]}
							List tempList = new ArrayList<>();
							Map<String, Object> mapTemp = new HashMap<String, Object>();
							if (macs.getJSONObject(k).containsKey("battery")) {
								mapTemp.put("dBattery", macs.getJSONObject(k).getString("battery"));
							}
							mapTemp.put("deviceId", macs.getJSONObject(k).getString("mac"));
							mapTemp.put("dataTime", CommonUtil.getCurrTimes());
							mapTemp.put("scanner", scannerMac);
							tempList.add(mapTemp);
							locationData.put("locationData", tempList);
							locationData.put("dataSource", "guihua");
							locationData.put("localFlag", localFlag);
							logger.debug(" locationData " + JSONObject.fromObject(locationData).toString());
							this.pushHbeaconInfo(JSONObject.fromObject(locationData).toString()); // push位置数据
						}
						if ("calling".equals(type)) {
							Map<String, Object> callingData = new HashMap<String, Object>();
							// 数据样例
							// {"callingData":[{"callingTime":1491960821,"deviceId":"fe2bbd1985c7",,"scannerId":"f000000000"}]}
							List tempList = new ArrayList<>();
							Map<String, Object> mapTemp = new HashMap<String, Object>();
							mapTemp.put("deviceId", macs.getJSONObject(k).getString("mac"));
							mapTemp.put("callingTime", CommonUtil.getCurrTimes());
							mapTemp.put("eventType", macs.getJSONObject(k).getString("type"));
							mapTemp.put("scannerId", scannerMac);
							tempList.add(mapTemp);
							callingData.put("callingData", tempList);
							callingData.put("dataSource", "guihua");
							if (object.containsKey("id")) {
								callingData.put("dataId", object.getString("id"));
							}
							callingData.put("localFlag", localFlag);
							logger.debug("calling Data " + JSONObject.fromObject(callingData).toString());
							this.pushHbeaconInfo(JSONObject.fromObject(callingData).toString());
						}
						// 处理桂花数据 end
					} // end for k
				} // end for j
			} // end contains data

			// 华米设备心跳数据
			if (object.containsKey("scannerHeartbeat")) {
				// 首次或者时间比较在一分钟内或者是大于十分钟进行发送心跳数据
				if ((ActionContextHolder.getHuamiDateFlag() == 0)
						|| (CommonUtil.getCurrTimes() - ActionContextHolder.getHuamiDateFlag() >= dateInterval
								&& CommonUtil.getCurrTimes() - ActionContextHolder.getHuamiDateFlag() <= dateInterval
										+ 1)
						|| (CommonUtil.getCurrTimes() - ActionContextHolder.getHuamiDateFlag() >= dateInterval * 2)
						|| (CommonUtil.getCurrTimes() - ActionContextHolder.getHuamiDateFlag() >= dateInterval * 10)) {
					ActionContextHolder.setHuamiDateFlag(CommonUtil.getCurrTimes());
					Map<String, Object> dataMap = new HashMap<String, Object>();// 最终数据
					JSONArray data = object.getJSONArray("scannerHeartbeat");
					List dataList = new ArrayList<>();
					for (int j = 0; j < data.size(); j++) {
						Map<String, Object> mapTemp = new HashMap<String, Object>();
						mapTemp.put("deviceId", data.getJSONObject(j).getString("scanner"));
						mapTemp.put("dataTime", CommonUtil.getCurrTimes());
						dataList.add(mapTemp);
					}
					if (dataList.size() > 0) {
						dataMap.put("deviceData", dataList);
						dataMap.put("dataSource", "huami");
						dataMap.put("localFlag", localFlag);
						String pushDataJson = JSONObject.fromObject(dataMap).toString();
						this.pushHbeaconInfo(pushDataJson);
					}
				}
			} // end contains heart
		} // end for i
	}

	/**
	 * 弃用
	 * 
	 * @author huibati
	 * @param 2017年9月6日
	 */
	public void pushHbeaconInfo() {
		logger.debug("start push device Data ");
		String dataUrl = properties.getProperty("hbeacon.local.pushDataurl");
		String dateInterval = properties.getProperty("hbeacon.local.pushData.dateInterval");
		String dataJson = "";
		List<LocalDevice> dataList = new ArrayList<>();
		Map<String, Object> dataMap = new HashMap<String, Object>();// 最终数据
		List tempList = new ArrayList<>();
		try {
			Integer endDate = CommonUtil.getCurrTimes();
			Integer startDate = endDate - Integer.parseInt(dateInterval); // 上传查询时间间隔内的数据
			String query = "select rp from LocalDevice rp where rp.createTime>=?1 and rp.createTime<=?2";
			dataList = this.em.createQuery(query).setParameter(1, startDate).setParameter(2, endDate).getResultList();
			if (dataList != null && dataList.size() > 0) {
				// 推送json数据
				// {"deviceData":[{"deviceId":"fx000000000","dataTime":666666},{"deviceId":"fx000000001","dataTime":666666}]}
				for (LocalDevice data : dataList) {
					if (data != null) {
						Map<String, Object> mapTemp = new HashMap<String, Object>();
						mapTemp.put("deviceId", data.getCode());
						mapTemp.put("dataTime", data.getCreateTime().toString());
						tempList.add(mapTemp);
					}
				}
				if (tempList.size() > 0) {
					dataMap.put("deviceData", tempList);
					dataJson = JSONObject.fromObject(dataMap).toString();
				}
			}
			if (dataJson != null && !"".equals(dataJson)) {
				HttpRequestUtil.postData(dataUrl, dataJson);
			}
		} catch (Exception e) {
			logger.debug("push device Data  error: " + e);
		}
	}

	/**
	 * 向服务器发送json数据
	 * 
	 * @author huibati
	 * @param 2017年9月6日
	 */
	public void pushHbeaconInfo(String dataJson) {
		logger.debug("start push LocalDevice  Data " + dataJson);
		String dataUrl = properties.getProperty("hbeacon.local.pushDataurl");
		try {
			HttpRequestUtil.postData(dataUrl, dataJson);
		} catch (Exception e) {
			logger.debug("push device  Data  error: " + e);
		}
	}

	/**
	 * 删除本地数(弃用)
	 * 
	 * @author huibati
	 * @param 2017年9月6日
	 */
	@Transactional
	public void deleteHbeaconData(Integer date) {
		try {
			logger.debug("start delete LocalDevice Data ");
			String queryBed = "delete from LocalDevice rp where rp.createTime< ?1";
			this.em.createQuery(queryBed).setParameter(1, date).executeUpdate();
		} catch (Exception e) {
			logger.debug("delete device Data  error: " + e);
		}
	}

	/**
	 * 处理接受桂花扫描器数据
	 * 
	 * @author huibati
	 * @param 2017年9月6日
	 */
	public void receiveScannerStatus(String dataJson) {
		logger.debug("receiveScannerStatus: " + dataJson + "  " + CommonUtil.getCurrTimeForString());
		JSONArray jsonArray = JSONArray.fromObject("[" + dataJson + "]");
		Map<String, Object> scannerData = new HashMap<String, Object>();
		List dataList = new ArrayList<>();
		for (int i = 0; i < jsonArray.size(); i++) {
			JSONObject object = jsonArray.getJSONObject(i);
			String scanners = object.getString("scanner");
			String[] scannerList = scanners.replace("\"", "").replace("[", "").replace("]", "").replaceAll(":", "")
					.split(",");
			for (String scanner : scannerList) {
				if (scanner != null && !"".equals(scanner)) {
					Map<String, Object> mapTemp = new HashMap<String, Object>();
					mapTemp.put("status", object.getString("status"));
					mapTemp.put("dataTime", CommonUtil.getCurrTimes());
					mapTemp.put("scanner", scanner);
					dataList.add(mapTemp);
				}
			}
		} // end for i
		scannerData.put("scannerStatus", dataList);
		String pushData = JSONObject.fromObject(scannerData).toString();
		logger.debug(" scannerData " + pushData);
		String dataUrl = properties.getProperty("hbeacon.local.pushDataurl");
		HttpRequestUtil.postData(dataUrl, pushData); // push扫描器数据
	}

	/**
	 * 处理接受桂花震动结果数据
	 * 
	 * @author huibati
	 * @param 2017年9月6日
	 */
	public void receiveCallingResult(String dataJson) {
		logger.debug("receiveCallingResult: " + dataJson + "  " + CommonUtil.getCurrTimeForString());
		JSONArray jsonArray = JSONArray.fromObject("[" + dataJson + "]");
		Map<String, Object> resultData = new HashMap<String, Object>();
		List dataList = new ArrayList<>();
		for (int i = 0; i < jsonArray.size(); i++) {
			JSONObject object = jsonArray.getJSONObject(i);
			Iterator<String> it = object.keys();
			Map<String, Object> mapTemp = new HashMap<String, Object>();
			while (it.hasNext()) {
				// key就是设备号
				String key = it.next();
				if ("id".equals(key) || "version".equals(key) || "timestamp".equals(key)) {
					continue;
				}
				mapTemp.put(key.replace(":", ""), object.getString(key));
			}
			mapTemp.put("version", object.getString("version"));
			mapTemp.put("timestamp", object.getString("timestamp"));
			dataList.add(mapTemp);
		}
		resultData.put("callingResult", dataList);
		String pushData = JSONObject.fromObject(resultData).toString();
		logger.debug(" callingResult   " + pushData);
		String dataUrl = properties.getProperty("hbeacon.local.pushDataurl");
		HttpRequestUtil.postData(dataUrl, pushData);
	}

	public void sendLocalServer() {
		Map<String, Object> resultData = new HashMap<String, Object>();
		String localFlag = properties.getProperty("hbeacon.local.flag");
		resultData.put("localFlag", localFlag);
		String pushData = JSONObject.fromObject(resultData).toString();
		String dataUrl = properties.getProperty("hbeacon.local.pushHeartDataurl");
		HttpRequestUtil.postData(dataUrl, pushData);
	}
	
	
	/**
	 * 获取摄像头数据
	 * 
	 * @author huibati
	 * @param 2017年9月6日
	 */
	public void getCameraData() {
		List dataListI=new ArrayList<>();
		List dataListU=new ArrayList<>();
		String dataUrl = properties.getProperty("local.camera.dataUrl"); 
		String tenantCode = properties.getProperty("local.tenantCode");
		String cameraData = HttpRequestUtil.sendGet(dataUrl+"?code="+tenantCode);// 获取最新对应关系
		logger.debug("netData:" + cameraData);
		String relationsDatas = "";
		if (cameraData == null||"".equals(cameraData)) {
			cameraData = "";
		} else {
			//JSONObject jasonObject = JSONObject.fromObject(cameraData);
			JSONArray datas= JSONArray.fromObject(cameraData);
			for (int i = 0; i < datas.size(); i++) {
				JSONObject jasonObject = datas.getJSONObject(i);
				 String code=jasonObject.getString("code");
				 String accessName=jasonObject.getString("accessName"); //接入用户名
				 String accessPass=jasonObject.getString("accessPass"); //接入密码
				 String ip=jasonObject.getString("ip");// ip地址
				 String port=jasonObject.getString("port");// 端口号
				 String uri=jasonObject.getString("uri");
				 Camera camera = this.cameraService.findByCode(code);
				 if(camera!=null){
					 camera.setCode(code);
					 camera.setIp(ip);
					 camera.setPort(Integer.parseInt(port));
					 camera.setAccessName(accessName);
					 camera.setAccessPass(accessPass);
					 camera.setUri(uri);
					 dataListU.add(camera); 
				 }else{
					 camera= new Camera();
					 camera.setCode(code);
					 camera.setIp(ip);
					 camera.setPort(Integer.parseInt(port));
					 camera.setAccessName(accessName);
					 camera.setAccessPass(accessPass);
					 camera.setUri(uri);
					 dataListI.add(camera); 
				 }
			}
		}
		if (dataListI.size() > 0) {
			commonService.batchInsert(dataListI);
		}
		if (dataListU.size() > 0) {
			commonService.batchUpdate(dataListU);
		}
		logger.debug("hbeaconData:" + relationsDatas);


	}
	
}
